1. /* slflsqrt.cpp by K.Tsuru */
  2. // function ID = 2004 DRADIX
  3. /*******************************************
  4. SLong class
  5. Get a square root of SLong N.
  6. *sgn = sign of (N - q*q). sgn >= 0
  7. If N is a complete square number, sgn = 0.
  8. *******************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. SLong LSqrt(const SLong& N, int* sgn){
  13. RealSize C;
  14. // change the effective figures for a time.
  15. uint ef = N.Head() + 1u;
  16. C.SetEffFig(ef, C.TEMP_EXTEND);
  17. SDouble sq(N);
  18. sq = DDAdd(Sqrt(sq), ROUND_DBL_INT); // use Newton method.
  19. SLong q, r;
  20. q = sq; // need the information of effective figures.
  21. C.SetEffFig(0); // restore the effective figures.
  22. r = N - q*q;
  23. if(r.Sign(2004) < 0){
  24. q -= 1.0; r = N - q*q;
  25. if( r.Sign() < 0 ) r.SetError(r.VERIFY, "LSqrt", 2004);
  26. }
  27. if(sgn != NULL) *sgn = r.Sign(); // = 1 or 0
  28. return q;
  29. }

slflsqrt.cpp : last modifiled at 2015/11/27 14:04:29(881 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).